package net.nandleon.AgenceVoyage.client.accueil.promotionCellule;

import net.nandleon.AgenceVoyage.client.ressources.Ressources;
import net.nandleon.AgenceVoyage.client.services.GestionDataService;
import net.nandleon.AgenceVoyage.client.services.GestionDataServiceAsync;
import net.nandleon.AgenceVoyage.shared.Promotion;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class PromotionCellule extends Composite {

	private static final Binder binder = GWT.create(Binder.class);
	interface Binder extends UiBinder<Widget, PromotionCellule> {}
	private final GestionDataServiceAsync gestionDataService = GWT.create(GestionDataService.class);
    static {
    	Ressources.INSTANCE.uiPromotionCelluleStyle().ensureInjected();  
    }
    
    @UiField
    Image miniaturePromo;
    
    @UiField
    Label titreMiniature;
    
    @UiField
    Label descriptionMiniature;
    
    public PromotionCellule(int numero){
		initWidget(binder.createAndBindUi(this));
		
		gestionDataService.getPromotion(numero,
                new AsyncCallback<Promotion>() {
                    @Override
                    public void onFailure(Throwable caught) {
                        Window.alert("Server communication error");
                    }

                    @Override
                    public void onSuccess(Promotion result) {
                    	miniaturePromo.setUrl(result.getUrlImage());
                    	miniaturePromo.setSize("40px", "40px");
                    	titreMiniature.setText(result.getTitreMiniature());
                		descriptionMiniature.setText(result.getDescriptionMiniature());

                    }
                });

    }
    

    
    
    
    
}
